<%--
  Created by IntelliJ IDEA.
  User: Mr.G
  Date: 2019/1/9
  Time: 18:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
</head>
<body>

<form class="layui-form" action="" lay-filter="yiqifrom" id="yiqifrom">
    <input type="hidden" id="yiqiname" name="yiqiname" class="layui-input">
    <table class="layui-table">
        <tbody>
        <tr>

            <td>开药医生：</td>
            <td>
                <select id="userId" name="userId" lay-search lay-filter="yisheng">
                    <option value="">选择医生</option>
                </select>
            </td>
            <td>病历编号:</td>
            <td>
                <select name="bingLiNum" id="caseNos" lay-filter="yq" lay-verify="required" lay-search="">
                    <option value="">直接选择或搜索选择</option>
                </select>
            </td>

        </tr>
        <tr>
            <td>客户号或会员号:</td>
            <td><input type="text" id="memberId" name="menberId" class="layui-input"></td>
            <td>选择药物</td>
            <td><button class="layui-btn" onclick="yptable()" type="button">选择药物</button></td>
        </tr>
        </tbody>
    </table>


    <%--药物数据表格--%>
    <table id="xzyptable" lay-filter="xzyptable"></table>
</form>
</body>


<script>

    var array = new Array();

    laydate.render({
        elem: '#reserveInstrStartDate',
        type: 'time'
        ,format: 'H点m分'
    });
    laydate.render({
        elem: '#reserveInstrFinishDate',
        type: 'time'
        ,format: 'H点m分'
    });


    //取出医生数据
    $.get("${path}/yuyuedengji/yishengList",function(data){
        // console.log(data)
        $.each(data,function(){
            var opt = $("<option></option>").appendTo("#userId");
            opt.text(this.username).val(this.userid);
        });
        layui.form.render()
    });
    //治疗仪列表
    $.get("${path}/bingliluru/zhiliaoyiList",function(data){
        $.each(data,function(){
            var optt = $("<option></option>").appendTo("#instrId");
            optt.text(this.instrName).val(this.instrId);
        });
        layui.form.render()
    });
    //取出病例列表
    $.get('${path}/bingliluru/getjiuzhen',function (data) {
        $.each(data,function(){
            var opt = $("<option></option>").appendTo("#caseNos");
            opt.text(this.medicalRecordNo).val(this.medicalRecordNo);
        });
        layui.form.render();
    });

    //监听治疗仪选择事件
    form.on('select(yiqimc)', function(data){
        $.get("${path}/bingliluru/zhiliaoyijiage",{instrId:data.value},function (jiage) {
            $("#price_min").val(jiage)

        })
    });
    
    function yptable() {
        $.get("${path}/bingliluru/yaowutable",function (str) {
            layui.layer.open({
                type: 1,
                title: '选择药物',
                area: '800px',
                maxmin: true,
                content : str,
                btn:['确定','取消'],
                yes:function (index) {

                    //获取选中行
                    var rows = table.checkStatus('yptable');
                    var data = rows.data;

                    if(data.length == 0){
                        layer.msg('请选择要药品',function () {});
                        return;
                    }

                    if (array.length == 0){
                        array  = data;
                    }else{
                        for(var u of data){
                            array.push(u)
                        }

                    }

                    console.log(array)

                    //渲染表格
                    table.render({
                        elem: '#xzyptable',
                        url: '',
                        page:true,
                        even: true,
                        cols:[[
                            {field:'ypid',title:'标号'},
                            {field:'ypname',title:'药品名称'},
                            {field:'zyc',title:'制药厂'},
                            {field:'ypdw',title:'药品单位',},
                            {field:'ypshuoming',title:'药品说明'},
                            {field:'yplsj',title:'药品零售价(元)'},
                            {field:'number', title:'数量',templet:function (d) {
                                    return "<input type=\"text\" style=\"height: 100%\" class=\"layui-input ypnumber\">";
                                }}
                        ]]
                        ,data:array
                    })

                    layui.layer.close(index)

                }
            })
        })
    }



</script>

</html>
